let countdown;
let remainingTime = 50;

function startCountdown() {
    clearInterval(countdown);
    countdown = setInterval(() => {
        if (remainingTime <= 0) {
            if (remainingTime === 0) {
                clearInterval(countdown);
                AndroidInterface.onFinished('task_id');
            }
        } else {
            remainingTime--;
            document.getElementById('timer').textContent = remainingTime;
        }
    }, 1000);
}

function onSaveData() {
    return remainingTime
}

function onRestoreData(data) {
    remainingTime = data;
    startCountdown();
}

startCountdown();